package it.asvp.asvp_portal.service.services.impl;

import it.asvp.asvp_portal.asvp_util.enumerative.RoleName;
import it.asvp.asvp_portal.asvp_util.util.DateUtils;
import it.asvp.asvp_portal.data.dao.RoleDao;
import it.asvp.asvp_portal.data.entity.member.Role;
import it.asvp.asvp_portal.service.services.AdminService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
public class AdminServiceImpl implements AdminService {

  @Autowired
  RoleDao roleDao;

  @Override
  @Transactional
  public Long[] createRoles() {
    Long[] rolesId = new Long[4];

    Role admin = new Role();
    admin.setRoleName(RoleName.ADMIN);
    admin.setDescription("ruolo di amministratore del sistema");
    admin.setCreatedOn(DateUtils.getCurrentDate());
    admin.setLastUpdate(DateUtils.getCurrentDate());
    rolesId[0] = roleDao.persist(admin).getId();

    Role presidente = new Role();
    presidente.setRoleName(RoleName.PRESIDENTE);
    presidente.setDescription("ruolo di presidente del sistema");
    presidente.setCreatedOn(DateUtils.getCurrentDate());
    presidente.setLastUpdate(DateUtils.getCurrentDate());
    rolesId[1] = roleDao.persist(presidente).getId();

    Role consigliere = new Role();
    consigliere.setRoleName(RoleName.CONSIGLIERE);
    consigliere.setDescription("ruolo di consigliere del sistema");
    consigliere.setCreatedOn(DateUtils.getCurrentDate());
    consigliere.setLastUpdate(DateUtils.getCurrentDate());
    rolesId[2] = roleDao.persist(consigliere).getId();

    Role socio = new Role();
    socio.setRoleName(RoleName.SOCIO);
    socio.setDescription("ruolo di socio del sistema");
    socio.setCreatedOn(DateUtils.getCurrentDate());
    socio.setLastUpdate(DateUtils.getCurrentDate());
    rolesId[3] = roleDao.persist(socio).getId();

    return rolesId;
  }
}
